package sorting

import "gitee.com/guuzaa/sorting/constraints"

func BubbleSort[T constraints.Ordered](arr []T) []T {
	if len(arr) < 2 {
		return arr
	}

	flag := true

	for i := 1; i < len(arr) && flag; i++ {
		flag = false
		for j := 0; j < len(arr)-i; j++ {
			if arr[j] > arr[j+1] {
				arr[j], arr[j+1] = arr[j+1], arr[j]
				flag = true
			}
		}
	}

	return arr
}
